package com.leo;

import com.jfoenix.controls.JFXProgressBar;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Duration;

import java.net.URL;

/**
 * @ClassName JFXProgressBarDemo
 * @Description
 * @Author wangss
 * @date 2020.11.26 12:07
 * @Version 1.0
 */
public class JFXProgressBarDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        JFXProgressBar jfxBar = new JFXProgressBar();
        jfxBar.setPrefWidth(500);
        JFXProgressBar jfxBarInf = new JFXProgressBar();
        jfxBarInf.setPrefWidth(500);
        jfxBarInf.setProgress(-1.0f);
        Timeline timeline = new Timeline(
                new KeyFrame(Duration.ZERO, new KeyValue(jfxBar.progressProperty(), 0), new KeyValue(jfxBar.progressProperty(), 0)),
                new KeyFrame(Duration.seconds(2), new KeyValue(jfxBarInf.progressProperty(), 1), new KeyValue(jfxBarInf.progressProperty(), 1)));
        timeline.setCycleCount(Timeline.INDEFINITE);
        timeline.play();

        AnchorPane an = new AnchorPane();
        an.getChildren().addAll(jfxBar, jfxBarInf);

        AnchorPane.setTopAnchor(jfxBar, 20.0);
        AnchorPane.setLeftAnchor(jfxBar, 20.0);

        AnchorPane.setTopAnchor(jfxBarInf, 40.0);
        AnchorPane.setLeftAnchor(jfxBarInf, 20.0);

        Scene scene = new Scene(an);
        URL url = this.getClass().getResource("/css/myStyle.css");
        scene.getStylesheets().add(url.toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.setWidth(800);
        primaryStage.setHeight(650);
        primaryStage.setTitle("JFoeniX测试");
        primaryStage.show();
    }
}
